//
//  WQCUpateViewController.m
//  renxinghuan
//
//  Created by 王晓民 on 2018/4/27.
//  Copyright © 2018年 吴清翠. All rights reserved.
//

#import "WQCUpateViewController.h"
#import "configuration.h"
@interface WQCUpateViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView * tableView;
@property(nonatomic,strong)NSArray *titleSource;
@property(nonatomic,strong)UITextField *wxTextField;
@property(nonatomic,strong)UITextField *qqTextField;
@property(nonatomic,strong)UITextField *addTextField;
@property(nonatomic,strong)UITextField *comanyTextField;
@property(nonatomic,strong)UITextField *misTextField;

@end

@implementation WQCUpateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController .navigationBarHidden = NO;
    _titleSource = @[@"申请类型",@"申请人姓名",@"联系电话",@"微信号",@"QQ号",@"所在地区",@"公司名称",@"我的期望"];

    [self setupNav];
    [self setupTableView];
    
}
#pragma mark ------>>创建tableview
- (void)setupTableView{
    
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavHeight, ScreenWidth,ScreenHeight-64) style:UITableViewStyleGrouped];
    self.tableView.backgroundColor = WYCGlobalBg;
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
    [self.view addSubview:self.tableView];
    UIButton * loginButton = [[UIButton alloc] init];
    loginButton.frame = CGRectMake(40 * px, ScreenHeight-70, ScreenWidth - 80 * px, 150 * px);
    loginButton.backgroundColor = wycMain;
    loginButton.layer.cornerRadius = 3;
    [loginButton setTitle:@"提交申请" forState:UIControlStateNormal];
    loginButton.titleLabel.font = [UIFont systemFontOfSize:72 * px];
    [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [loginButton addTarget:self action:@selector(returnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginButton];

}
//提交申请
-(void)returnClick
{
    [SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
    [SVProgressHUD setForegroundColor:[UIColor whiteColor]]; //字体颜色
    [SVProgressHUD setBackgroundColor:[UIColor blackColor]];   //背景颜色
    if (self.wxTextField.text.length==0) {
        [SVProgressHUD showImage:nil status:@"微信号不能为空"];
        return;
    }
    else if (self.qqTextField.text.length == 0)
    {
        [SVProgressHUD showImage:nil status:@"QQ号不能为空"];
        return;
    }
    else if (self.addTextField.text.length==0)
    {
        [SVProgressHUD showImage:nil status:@"住址不能为空"];
        return;
    }
    else if (self.comanyTextField.text.length==0)
    {
        [SVProgressHUD showImage:nil status:@"公司名字不能为空"];
        return;
    }
    else
    {
    NSMutableDictionary * params = [NSMutableDictionary dictionary];
    params[@"name"] = [WYCAccountTool unarchiveuserName] ;
    params[@"mobile"] = [WYCAccountTool unarchivemobile];
    params[@"wechat"] = self.wxTextField.text;
    params[@"qqNumber"] = self.qqTextField.text;
    params[@"address"] = self.addTextField.text;
    params[@"companyName"] = self.comanyTextField.text;
    params[@"comment"] = self.misTextField.text;


    [HttpTool POST:applicationAgent params:params success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        
        if ([[responseObject objectForKey:@"code"] intValue] == 0)
        {
            
            [SVProgressHUD showImage:nil status:@"提交申请成功"];
        }
        else
        {
            [SVProgressHUD showImage:nil status:responseObject[@"message"]];

        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showImage:nil status:Failed];
        
    }];
    }
    
}
- (void)setupNav {
    [self.navigationController.navigationBar setBarTintColor:wycMain];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    self.navigationItem.title = @"我要申请";
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1 ;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.titleSource.count ;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *identifer=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifer];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer];
    }
    
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.text = [_titleSource objectAtIndex:indexPath.row];
    if (indexPath.row == 0) {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.keyboardType = UIKeyboardTypeNumberPad;
        bankNum.text = @"代理商";
        bankNum.enabled = NO;
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bankNum];
    }
    if (indexPath.row == 1) {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, ScreenWidth-110, 30);
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.text = [WYCAccountTool unarchiveuserName];
        bankNum.font = [UIFont systemFontOfSize:14];
        bankNum.enabled = NO;
        [cell.contentView addSubview:bankNum];
        
        
    }
    else if (indexPath.row ==2)
    {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.text =[WYCAccountTool unarchivemobile];
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.font = [UIFont systemFontOfSize:14];
        bankNum.enabled = NO;
        [cell.contentView addSubview:bankNum];
    }
    else if (indexPath.row ==3)
    {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.placeholder = @"请输入微信号";
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.keyboardType = UIKeyboardTypeNumberPad;
        bankNum.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bankNum];
        self.wxTextField=bankNum;
    }
    else if (indexPath.row ==4)
    {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.placeholder = @"请输入QQ号";
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.keyboardType = UIKeyboardTypeNumberPad;
        bankNum.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bankNum];
        self.qqTextField=bankNum;

    }
    else if (indexPath.row ==5)
    {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.placeholder = @"请输入所在地区";
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.keyboardType = UIKeyboardTypeDefault;
        bankNum.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bankNum];
        self.addTextField=bankNum;

    }
    else if (indexPath.row ==6)
    {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.placeholder = @"请输入公司名称";
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.keyboardType = UIKeyboardTypeDefault;
        bankNum.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bankNum];
        self.comanyTextField=bankNum;

    }
    else if (indexPath.row ==7)
    {
        UITextField  *bankNum = [[UITextField alloc]init];
        bankNum.frame = CGRectMake(110, 10, 250, 30);
        bankNum.placeholder = @"请输入您的期望";
        bankNum.textAlignment = NSTextAlignmentLeft;
        bankNum.keyboardType = UIKeyboardTypeNumberPad;
        bankNum.font = [UIFont systemFontOfSize:14];
        [cell.contentView addSubview:bankNum];
        self.misTextField=bankNum;

    }
    
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
